package gs.eisenhower.swallet.utils.common;

import org.acra.ACRA;
import org.acra.annotation.ReportsCrashes;

import com.crittercism.app.Crittercism;

import android.app.Application;
import android.content.Context;

/**
 * @author mbadarau
 * 
 * @RTR You can view the published form here: https://docs.google.com/spreadsheet/viewform?formkey=dGQ0YUVXc1BKbUp4WDNpRFVmVURuaHc6MQ
 */
@ReportsCrashes(formKey = "dGQ0YUVXc1BKbUp4WDNpRFVmVURuaHc6MQ") 
public class AppController extends Application {

    @Override
    public void onCreate() {
        initContext();
        SharedPreferencesSingleton.initContext(getContext());
        /**
         * @RTR added ACRA for crash reports 
         */
        // The following line triggers the initialization of ACRA
        ACRA.init(this);
        
        /**
         * @RTR added Crittercism for better crash reports 
         */
        Crittercism.init(getApplicationContext(), "50fd48774f633a45bf000008");
        
        super.onCreate();
    }
 
    private static AppController INSTANCE = null;

    /**
     * Prepare the singletons.
     */
    private void initContext() {
        prepInstance(this);
    }

    private void prepInstance(AppController appContext) {
        if (INSTANCE == null && appContext != null) {
            INSTANCE = appContext;
        }
    }

    public static final AppController getInstance() {
        return INSTANCE;
    }

    public static final Context getContext() {
        return getInstance().getApplicationContext();
    }

}
